/**
 * 和飞信客户端API
 */

export default {
    install (Vue, options) {
        window.fxAPI = {
            index: 0,
            backs: [],
            ai: null,
            api: function (c, d, a) {
                this.index++;
                this.backs[this.index] = a;
                if (!this.ai) {
                    if (window.navigator.WebContainer) {
                        this.ai = window.navigator.WebContainer
                    } else {
                        if (window.WebContainer) {
                            this.ai = window.WebContainer
                        } else {
                            return false
                        }
                    }
                }
                switch (c) {
                    case "forSetTime":
                        this.ai[c](d.type, this.index, "fxAPIBack");
                        break;
                    case "getEnterpriseContact":
                        this.ai[c](this.index, "fxAPIBack");
                        break;
                    case "selectEnterpriseContact":
                        this.ai[c](d.title, this.index, "fxAPIBack");
                    case "selectEnterpriseContactMulti":
                        this.ai[c](d.title, d.num.toString(), this.index, "fxAPIBack", "[" + d.selected.toString() + "]");
                        break;
                    case "getLocalContactsList":
                        this.ai[c](this.index, "fxAPIBack");
                        break;
                    case "setAppTitle":
                        this.ai[c](d.title);
                        break;
                    case "selectFile":
                        this.ai[c](d.type, d.isMultiSelect, this.index, "fxAPIBack");
                        break;
                    case "startMultiVoiceCall":
                        var b = {
                            contactListArray: d,
                            backId: this.index,
                            backFunc: "fxAPIBack"
                        };
                        this.ai[c](b);
                        break
                }
            }
        };
        window.fxAPIBack = function (a, b) {
            typeof fxAPI.backs[a] == "function" && fxAPI.backs[a](b)
        };
    }
}